﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.OleDb;

public partial class edit_room : System.Web.UI.Page
{
    OleDbConnection conx;
    string pk;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (DropDownList2.SelectedValue == "N")
        {
            DropDownList3.Enabled = false;
            //DropDownList3.SelectedValue = "";
        }
        else
            DropDownList3.Enabled = true;
    }
    protected void edit_Click(object sender, EventArgs e)
    {
        if (GridView1.SelectedIndex == -1)
        {
            LabelSelected.Text = "\"Please Seleted Row !\"";
            return;
        }
        else
        {
            pk = GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text;
            TextBox1.Text = pk;
            MultiView1.ActiveViewIndex = 1;

            //TextBox1.Text = GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text;
            //TextBox2.Text = GridView1.Rows[GridView1.SelectedIndex].Cells[4].Text;
            //TextBox3.Text = GridView1.Rows[GridView1.SelectedIndex].Cells[6].Text;
            //TextBox4.Text = GridView1.Rows[GridView1.SelectedIndex].Cells[5].Text;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        try
        {
            String con = "Provider=MSDAORA;Data Source=orcl;Password=oracle;User ID=pearl";//"DSN=orcl;Driver={Microsoft ODBC for Oracle};UID=system;PWD=password;SERVER=localhost;";
            conx = new OleDbConnection(con);
            conx.Open();

            if (conx.State == ConnectionState.Open)
            {
                pk = GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text;
                
                string tb1 = TextBox1.Text;
                string ddl1 = DropDownList1.SelectedValue;
                string ddl2 = DropDownList2.SelectedValue;
                string ddl3 = DropDownList3.SelectedValue;

                OleDbCommand ODC = new OleDbCommand("UPDATE ROOMS SET ROOM_NO = '" + tb1 + "', ROOM_TYPE_ID = '" + ddl1 + "', STATUS = '" + ddl2 + "',GUEST_ID = '" + ddl3 + "' WHERE ROOM_NO = '" + pk + "'", conx);
                ODC.ExecuteNonQuery();
                OleDbCommand ODC2 = new OleDbCommand("COMMIT", conx);
                ODC2.ExecuteNonQuery();
                Label1.Text = "\"  DATA UPDATED\"";

                TextBox1.Text = "";
            }
            else
                Label1.Text = "Oracle Connect Failed";
        }

        catch (Exception ex)
        {
            Label1.Text = ex.Message + "<br />" + ex.StackTrace;
        }

        finally
        {
            conx.Close();
            conx = null;
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
    }

    protected void Back_Click(object sender, EventArgs e)
    {
        if (MultiView1.ActiveViewIndex == 1)
        {
            MultiView1.ActiveViewIndex = 0;
        }
        else
            Response.Redirect("room.aspx");
    }

}